  <template>
  <div class="songlist">
    <div class="header">
      <div
        class="mask"
        :style="`backgroundImage:url(${news.coverImgUrl})`"
      ></div>
      <div class="box">
        <div class="top">
          <img :src="news.coverImgUrl" />
          <div class="gd">歌单</div>
          <div class="num">
            {{ news.playCount | formatNum }}
          </div>
        </div>
        <div class="text">
          <h2>
            {{ news.name }}
          </h2>
          <div class="user">
            <img class="tx" :src="users.avatarUrl" />
            {{ users.nickname }}
          </div>
        </div>
      </div>
    </div>

    <h3>歌曲列表</h3>
    <music-song :currentmusic="currentmusic" :musiclist="songs" @play="$emit('play', $event)"></music-song>
    <div class="ck">查看更多歌曲，请下载客户端</div>
    <h4>精彩评论</h4>
    <ul class="pl">
      <li v-for="com in commentList" :key="com.commentId">
        <div class="left_t">
          <img :src="com.user.avatarUrl" alt="" />
        </div>

        <div class="right_c">
          <div class="name_t">
            <div class="name_l">
              <p>
                {{ com.user.nickname }}
              </p>
              <span class="times">
                {{ com.timeStr }}
              </span>
            </div>
            <div class="name_r">
              {{ num }}
              <img
                src="@/assets/未点赞.png"
                :style="{ width: '14px', height: '14px' }"
                alt=""
              />
            </div>
          </div>
          <div class="commnets">
            {{ com.content }}
          </div>
        </div>
      </li>
    </ul>
  </div>
</template>

<script>
import MusicSong from "../components/MusicSong.vue";
export default {
  props: {
    currentmusic: {
      type: Object,
      default: () => {
        return null;
      },
    },
    listid: {
      type: String,
      default: "0",
    },
  },
  components: { MusicSong },
  data() {
    return {
      news: [],
      songs: [],
      users: [],
      commentList: [],
      myStyle: "",
      num: 100,
    };
  },
  created() {
    this.getSong();
  },
  methods: {
    getSong() {
      this.axios.get("/playlist/detail?id=" + this.listid).then((re) => {
        console.log("获取歌单===>", re);
        this.songs = re.playlist.tracks.map((item) => {
          item.song = {
            album: item.al,
            alias: item.alia,
            artists: item.ar,
            privilege: item.privilege,
          };
          return item;
        });
        console.log("re,playlist.creator==>", re.playlist.creator);
        this.news = re.playlist;
        this.users = re.playlist.creator;
        this.myStyle = re.playlist.creator.backgroundUrl;
        console.log("songs==>", this.songs);
      });
      this.axios.get("/comment/playlist?id=" + this.listid).then((re) => {
        console.log("获取评论===>", re);
        this.commentList = re.comments;
      });
      this.axios.get("/simi/user?id=" + this.listid).then((re) => {
        console.log("获取用户信息===>", re);
      });
    },
  },
  filters: {
    formatNum(value) {
      let val = Math.floor(value / 1000);
      return val / 10 + "万";
    },
  },
  // beforeRouterEnter(to, from, next) {
  //   console.log("beforeRouterEnter");
  //   next((vm) => {
  //     vm.axios.get("/playlist/detail?id=" + vm.listid).then((re) => {
  //       console.log("re==>", re);
  //       this.songList = re.playlist;
  //     });
  //   });
  // },
};
</script>

<style lang="scss" scoped>
.songlist {
  width: 100%;
  .header {
    width: 100%;
    height: 186px;
    display: flex;
    align-items: center;
    // background-image: linear-gradient(45deg, gray, pink);
    position: relative;
    overflow: hidden;
    .mask {
      background-repeat: no-repeat;
      background-size: cover;
      position: absolute;
      background-position: 50%;
      left: 0;
      top: 0;
      right: 0;
      bottom: 0;
      z-index: 1;
      filter: blur(20px);
      transform: scale(1.5);
      &::after {
        content: " ";
        background-color: rgba(0, 0, 0, 0.25);
        position: absolute;
        left: 0;
        top: 0;
        right: 0;
        bottom: 0;
        z-index: 1;
      }
    }
    .box {
      width: 100%;
      height: 126px;
      position: absolute;
      z-index: 2;
      display: flex;
      .text {
        width: 100%;
        height: 126px;
        margin-left: 16px;
        padding-left: 3px;
        color: white;
        .user {
          height: 30px;
          display: flex;
          align-items: center;
          .tx {
            width: 30px;
            height: 30px;
            border-radius: 50%;
          }
        }

        h2 {
          width: 208px;
          font-size: 17px;
          color: #fefefe;
          height: 44px;
          padding-top: 1px;
          font-weight: normal;
        }
      }
      .top {
        width: 126px;
        height: 126px;
        position: relative;
        background-color: #e2e2e3;
        margin-left: 20px;
        img {
          width: 126px;
          height: 126px;
        }
        .num {
          position: absolute;
          right: 2px;
          top: 0;
          z-index: 3;
          padding-left: 15px;
          color: #fff;
          font-size: 12px;
          background-position: 0;
          background-repeat: no-repeat;
          background-size: 11px 10px;
          text-shadow: 1px 0 0 rgb(0 0 0 / 15%);
          &::after {
            content: " ";
            position: absolute;
            left: 0;
            top: 0;
            width: 100%;
            height: 18px;
            z-index: 2;
            background-image: -webkit-linear-gradient(
              left,
              rgba(0, 0, 0, 0),
              rgba(0, 0, 0, 0.2)
            );
            background-image: linear-gradient(
              90deg,
              rgba(0, 0, 0, 0),
              rgba(0, 0, 0, 0.2)
            );
          }
        }
        .gd {
          position: absolute;
          z-index: 3;
          top: 10px;
          left: 0px;
          padding: 0 8px;
          height: 17px;
          color: #fff;
          font-size: 9px;
          text-align: center;
          line-height: 17px;
          background-color: rgba(217, 48, 48, 0.8);
          border-top-right-radius: 17px;
          border-bottom-right-radius: 17px;
        }
      }
    }

    // &::after {
    //   content: "";
    //   background-color: rgba(0, 0, 0, 0.25);
    //   position: absolute;
    //   top: 0;
    //   left: 0;
    // }
  }

  h3 {
    width: 100%;
    height: 23px;
    line-height: 23px;
    padding: 0 10px;
    font-size: 12px;
    color: #666;
    background-color: #eeeff0;
  }

  .ck {
    margin: 15px 0;
    color: #999;
    font-size: 14px;
    text-align: center;
  }

  h4 {
    color: #666;
    font-size: 12px;
    font-weight: 400;
    background: rgba(0, 0, 0, 0.05);
    padding: 0 10px;
    height: 23px;
    line-height: 23px;
  }

  .pl {
    width: 100%;
    li {
      width: 100%;
      margin: 10px 0;
      display: flex;
      .left_t {
        width: 30px;
        height: 100%;
        margin: 0 10px;
        img {
          width: 30px;
          height: 30px;
          border-radius: 50%;
          margin: 0 auto;
        }
      }

      .right_c {
        width: 100%;
        height: 100%;

        .name_t {
          width: 100%;
          height: 38px;
          display: flex;
          justify-content: space-between;
          .name_l {
            width: 250px;
            height: 100%;
            display: flex;
            flex-direction: column;
            p {
              font-size: 14px;
              color: #666;
              line-height: 20px;
            }
            span {
              font-size: 12px;
              color: #999;
            }
          }

          .name_r {
            margin-right: 10px;
          }
        }

        .commnets {
          padding: 5px;
        }
      }
    }
  }
}
</style>